package com.henry.config;

import com.henry.enums.ExchangeName;
import com.henry.enums.QueueNames;
import com.henry.enums.RoutingKeyName;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * topic模型config
 */
@Configuration
public class TopicConfig {

    @Bean
    public TopicExchange topicExchange() {
        return ExchangeBuilder.topicExchange(ExchangeName.TOPIC_EXCHANGE.name()).durable(true).build();
    }

    @Bean
    public Queue sms() {
        return new Queue(QueueNames.TOPIC_MSG_QUEUE_SMS.name(), true);
    }

    @Bean
    public Queue email() {
        return new Queue(QueueNames.TOPIC_MSG_QUEUE_EMAIL.name(), true);
    }


    @Bean
    public Binding smsBinding() {
        return BindingBuilder
                .bind(sms())
                .to(topicExchange())
                .with(RoutingKeyName.TOPIC_MSG_ROUTING_KEY_SMS.name());
    }

    @Bean
    public Binding emailBinding() {
        return BindingBuilder
                .bind(email())
                .to(topicExchange())
                .with(RoutingKeyName.TOPIC_MSG_ROUTING_KEY_EMAIL.name());
    }

}
